using System;
using System.Collections.Generic;
using System.Text;
using MCMLXVII.Client.Common.Session;
using MCMLXVII.BackEnd.Services.Common.Messages;
using MCMLXVII.BackEnd.Services.OrganizationChart.Messages;
using MCMLXVII.BackEnd.Services.SystemConfiguration.Messages;
using MCMLXVII.Core.Common;


namespace MCMLXVII.Tools.OrganizationChart
{
    class BusinessActions
    {

        public static bool LogonUser(string ToolName)
        { 
            return ToolSession.LogonUser(ToolName);        
        }

        public static string[] GetPermissions()
        {
            return ToolSession.GetPermissions();
        }



        public static msgOrganizationNodeInfo GetOrganizationTree()
        {
            return ToolSession.proxy.GetOrganizationTree(new msgVoidRequest());
        }

        public static msgOrganizationNodeInfo GetOrganizationDestinationTree (int SourceNodeID)
        {
            return ToolSession.proxy.GetOrganizationDestinationTree(new msgSimpleNodeRequest(SourceNodeID));
        }
            
        public static msgOrganizationTreeNodeMember[] GetOrganizationTreeNodeMembers( int NodeID )
        {
            return ToolSession.proxy.GetOrganizationTreeNodeMembers(new msgSimpleNodeRequest(NodeID)).GetArray();
        }

        public static int UpdateOrganizationTreeNode(msgUpdateOrganizationTreeNode req)
        {
            return ToolSession.proxy.UpdateOrganizationTreeNode(req).Item ;
        }
        
        public static int MoveOrganizationTreeNode(msgMoveNodeRequest req) 
        {
            return ToolSession.proxy.MoveOrganizationTreeNode(req).Item ;
        }

        public static int MoveOrganizationMember(msgMoveMemberRequest req)
        {
            return ToolSession.proxy.MoveOrganizationMember(req).Item;
        }
        public static int UpdateOrganizationMember(msgUpdateOrganizationMember req)
        {
            return ToolSession.proxy.UpdateOrganizationMember(req).Item;
        }

        public static bool DeleteOrganizationTreeNode (int NodeID )
        {
            return ToolSession.proxy.DeleteOrganizationTreeNode(new msgSimpleNodeRequest(NodeID)).Item;
        }

        public static bool DeleteOrganizationMember (msgSimpleMemberRequest req)
        {
            return ToolSession.proxy.DeleteOrganizationMember(req).Item;
        }

        public static msgOrganizationMemberInfo GetOrganizationMemberInfo(msgSimpleMemberRequest req)
        {
            return ToolSession.proxy.GetOrganizationMemberInfo(req);    
        }

        public static string[] GetOrganizationTreeNodeEfectiveRights(int NodeID)
        {
            return ToolSession.proxy.GetOrganizationTreeNodeEfectiveRights(new msgSimpleNodeRequest(NodeID)).GetArray();    
        }

        public static msgOrganizationNodeAuditInfo[] GetOrganizationTreeNodeAudit(int NodeID)
        {
            return ToolSession.proxy.GetOrganizationTreeNodeAudit(new msgSimpleNodeRequest(NodeID)).GetArray();
        }

        public static msgOrganizationMemberAuditInfo[] GetOrganizationMemberAudit(int NodeID, int MemberID)
        {
            return ToolSession.proxy.GetOrganizationMemberAudit(new msgSimpleMemberRequest(NodeID, MemberID)).GetArray();
        }
        public static msgXMLResponse GetDirectoryTree (int SecurityProviderID)
        {
            return ToolSession.proxy.GetDirectoryTree( new msgGenericItemRequest<int>(SecurityProviderID));        
        }

        public static msgXMLResponse GetDirectoryNodeUsers(msgSecurityUsersListRequest req)
        {
            return ToolSession.proxy.GetDirectoryNodeUsers(req);
        }

        public static msgXMLResponse GetDirectoryNodeGroups(msgSecurityUsersListRequest req)
        {
            return ToolSession.proxy.GetDirectoryNodeGroups(req);
        }

        public static msgMembershipInfo[] GetOrganizationTreeMembers(int ClassID, string FindPattern)
        {
            return ToolSession.proxy.GetOrganizationTreeMembers(new msgFindMembersRequest(ClassID, FindPattern)).GetArray();
        }

        public static msgMembershipInfo[] GetOrganizationTreeRoleMembers( int ClassID, string FindPattern)
        {
            return ToolSession.proxy.GetOrganizationTreeRoleMembers(new msgFindMembersRequest(ClassID, FindPattern)).GetArray();
        }


        public static msgMembershipInfo GetOrganizationTreeMemberDesc(int MemberID)
        {
            return ToolSession.proxy.GetOrganizationTreeMemberDesc(new msgGenericItemRequest<int>(MemberID));
        }

        public static msgLanguajesListResponse GetContentLanguagesList(bool ListAll)
        {
            return ToolSession.proxy.GetContentLanguagesList(new msgGenericItemRequest<bool>(ListAll));
        }

        public static string GetDefaultLanguage()
        {
            return ToolSession.proxy.GetDefaultLanguage(new msgVoidRequest()).Item ;
        }

        public static msgNewOrganizationTreeItemResponse CreateNewOrganizationTreeNode(msgNewOrganizationTreeNode req)
        {
            return ToolSession.proxy.CreateNewOrganizationTreeNode(req);
        }

        public static msgNewOrganizationTreeItemResponse CreateNewOrganizationMember(msgNewOrganizationMember req)
        {
            return ToolSession.proxy.CreateNewOrganizationMember(req);
        }

        public static msgOrganizationTreeMembersClass[] GetOrganizationTreeMembersClasses()
        {
            return ToolSession.proxy.GetOrganizationTreeMembersClasses(new msgVoidRequest()).GetArray();
        }

        public static msgBasicOrganizationMemberInfo[] FindorganizationMembersByDescription (string Filter)
        {
            return ToolSession.proxy.FindorganizationMembersByDescription(new msgGenericItemRequest<string>(Filter)).GetArray();
        }

        public static msgOrganizationTreeNodeSecurity GetOrganizationTreeNodeSecurity(int NodeID)
        {
            return ToolSession.proxy.GetOrganizationTreeNodeSecurity(new msgSimpleNodeRequest(NodeID));
        }

        public static int UpdateOrganizationTreeNodeSecurity(msgUpdateOrganizationTreeNodeSecurity req)
        {
            return ToolSession.proxy.UpdateOrganizationTreeNodeSecurity(req).Item ;
        }

        public static msgSecurityProvider[] GetEnabledSecurityProviders()
        {
            return ToolSession.proxy.GetEnabledSecurityProviders(new msgVoidRequest()).GetArray();       
        }



        #region permissions management
        public static msgToolsInfo[] GetToolsList()
        {
            return ToolSession.proxy.GetToolsList(new msgVoidRequest()).GetArray();
        }

        public static msgToolsInfo GetToolInfo(string ToolName)
        {
            return ToolSession.proxy.GetToolInfo(new msgGenericItemRequest<string>(ToolName));
        }

        public static msgPermissionInfo[] GetPermissionsList()
        {
            return ToolSession.proxy.GetPermissionsList(new msgVoidRequest()).GetArray();
        }

        public static msgPermissionInfo[] GetMemberPermissionsList(int MemberID)
        {
            return ToolSession.proxy.GetMemberPermissionsList(new msgGenericItemRequest<int>(MemberID)).GetArray();
        }

        public static msgPermissionInfo[] GetMemberInheritedPermissionsList(int MemberID)
        {
            return ToolSession.proxy.GetMemberInheritedPermissionsList(new msgGenericItemRequest<int>(MemberID)).GetArray();
        }

        public static int UpdateMemberPermissions(int MemberID, int UpdateSequence, int[] Permissions)
        {
            return ToolSession.proxy.UpdateMemberPermissions(new msgMemberPermissionInfo(MemberID, UpdateSequence, Permissions )).Item ;
        }

        #endregion



    }
}
